<?php
/**
 * 微校云主界面模型
 * Author: 孙武 QQ:1228746736
 * Date: 2017/11/1
 * Time: 10:37
 */

namespace Home\Model;
class TicketModel extends \Think\Model{

    /**
     * 根据出发地和目的地查询车次信息
     * @param $from 出发地
     * @param $to 目的地
     */
    public function getAddrsInfoByFromAndTo($from,$to)
    {
        $now=time();
        $info = M('addr')->where(array('addr_from' => $from, 'addr_to' => $to,'addr_status'=>1))->where("addr_depart_time>$now")->select();
        return $info;
    }

    /**
     * 获取车票的所需数目(商家填)
     * 比如说需要32人才能发车
     * @param $ticketId
     * @return mixed
     */
    public function getNeedNum($ticketId)
    {
        $sql = "select od_ticket_num as unit_price from bus_pre_order WHERE od_addr_id = $ticketId";
        $res = D()->query($sql);
        $total = 0;
        foreach ($res as $k => $v) {
            $total += $v['unit_price'];
        }
        return $total;
    }


}